FROM {{ namespace }}/{{ image_prefix }}openstack-base:{{ tag }}
LABEL maintainer="{{ maintainer }}" name="{{ image_name }}" build-date="{{ build_date }}"

{% block bifrost_base_header %}{% endblock %}

{% import "macros.j2" as macros with context %}

{{ macros.configure_user(name='bifrost') }}

{% if install_type == 'binary' %}

RUN echo '{{ install_type }} not yet available for {{ base_distro }}' && /bin/false

{% elif install_type == 'source' %}

ENV VENV /var/lib/kolla/venv

{% set bifrost_base_pip_packages = [
    '/bifrost'
] %}

ADD bifrost-base-archive /bifrost-base-source
COPY build_arg.yml /tmp/build_arg.yml
RUN ln -s bifrost-base-source/* bifrost \
    && {{ macros.install_pip(bifrost_base_pip_packages | customizable("pip_packages")) }}

WORKDIR /bifrost

{% if base_distro in ['debian', 'ubuntu'] %}
RUN sed -e "s/.*mariadb.*//Ig" -i /etc/apt/sources.list && apt-get purge -y mariadb* mysql*
{% endif %}

{% block bifrost_ansible_install %}
{% if base_distro in ['debian', 'ubuntu'] %}
RUN apt-get update && \
{% else %}
RUN echo " " && \
{% endif %}
    bash -c './scripts/env-setup.sh && source ./env-vars && \
    ansible-playbook -vvvv -i /bifrost/playbooks/inventory/target /bifrost/playbooks/install.yaml \
    -e @/tmp/build_arg.yml && \
{% if base_distro in ['debian', 'ubuntu'] %}
    apt-get clean && rm -rf /var/lib/apt/lists/*'
{% else %}
    yum clean all'
{% endif %}
{% endblock %}
{% endif %}

COPY bifrost_sudoers /etc/sudoers.d/kolla_bifrost_sudoers

RUN chmod 750 /etc/sudoers.d \
    && chmod 440 /etc/sudoers.d/kolla_bifrost_sudoers \
    && chown -R bifrost:bifrost /bifrost

{% block bifrost_base_footer %}{% endblock %}
